package cc.customer.web.MRecord;

import cc.customer.MRecord.service.MRecordService;
import cc.customer.common.domain.MRecord;
import cc.customer.common.domain.QueryRequest;
import cc.customer.system.domain.MyUser;
import cc.customer.system.service.UserService;
import cc.customer.web.sys.controller.base.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
@RequestMapping(value="mrecordPc")
public class MRecordController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(MRecordController.class);

    @Autowired
    private UserService userService;

    @Autowired
    private MRecordService mRecordService;

    /**初始化今日电话记录**/
    @RequestMapping(value = "/getPhoneCallList")
    @ResponseBody
    public Map<String,Object> getPhoneCallList(MRecord record, QueryRequest request){
        MyUser user = this.getCurrentUser();

        List<String> list = new ArrayList<>();
        /**人员查询**/
        try {
            String uuidsUser = record.getmUserid()+"";
            if (!StringUtils.isEmpty(uuidsUser)){
                List<String> listAll = Arrays.asList(uuidsUser.split(","));
                for (String uuids :listAll){
                    if (uuids.contains("jpet")){
                        String deptid = uuids.replace("jpet","");
                        MyUser userAll = new MyUser();
                        userAll.setDeptId(Long.valueOf(deptid));
                        userAll.setStatus("1");
                        List<MyUser> listall =  userService.selectUserByDeptid(userAll);
                        for (MyUser userss:listall){
                            list.add(userss.getUserUuid());
                        }
                    }else{
                        list.add(uuids);
                    }
                }
            }else{
                list.add(user.getUserUuid());
            }
            record.setmUserList(list);
            return super.selectByPageNumSize(request,() -> this.mRecordService.selectMRecord(record,user));
        }catch (Exception e){
            e.printStackTrace();
            return new HashMap<>();
        }
    }

}
